#!/bin/bash

# Docker 部署脚本
echo ==================================================
echo Script startup for deploy Docker
echo ==================================================

DOCKER_CE_VERSION=5:18.09.1~3-0~ubuntu-bionic
DOCKER_APT_REPOSITORY="deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
DOCKER_GPG_KEY_URL=https://download.docker.com/linux/ubuntu/gpg

############################ installing start ############################
echo -e "-------------------- installing\n"

echo "-------------------- updating apt source list"
sudo apt-get update
echo -e "-------------------- update success.\n"
sleep 3

echo "-------------------- installing apt-transport-https components"
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
echo -e "-------------------- install success.\n"
sleep 3

echo "-------------------- installing and adding GPG keys"
curl -fsSL $DOCKER_GPG_KEY_URL | sudo apt-key add -
echo -e "-------------------- install and add success.\n"
sleep 3

echo "-------------------- adding apt repository for docker to source.list"
sudo add-apt-repository $DOCKER_APT_REPOSITORY
echo -e "-------------------- add success.\n"
sleep 3

echo "-------------------- updating apt source list again"
sudo apt-get update
echo -e "-------------------- update again success.\n"
sleep 3

echo "-------------------- installing docker-ce"
sudo apt-get install -y docker-ce
echo -e "-------------------- install success.\n"
sleep 3

echo "-------------------- installing docker"
sudo apt-get install docker-ce=$DOCKER_CE_VERSION
echo -e "-------------------- install success.\n"
sleep 3

echo -e "-------------------- install completed!\n"
############################ installing end ############################

############################ version info start ############################
echo -e "-------------------- version info\n"
docker -v
sleep 3
############################ version info end ############################

############################ validating start ############################
echo -e "-------------------- validating\n"

echo -e "-------------------- validating docker run status\n"
systemctl status docker
sleep 3

echo -e "-------------------- validate completed!\n"
############################ validating end ############################

echo =================================================
echo Deploy Docker completed!
echo =================================================